package com.yzx.lifeassistants.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.baidu.mapapi.search.core.PoiInfo;
import com.yzx.lifeassistants.R;

/**
 * @Description: 美食列表适配器
 * @author: yzx
 * @time: 2016-3-11 下午8:02:51
 */
public class FoodInfoAdapter extends BaseAdapter {

	private List<PoiInfo> dataList;
	private PoiInfo data;
	private LayoutInflater inflater;
	private ViewHolder holder;

	public FoodInfoAdapter(Context context, List<PoiInfo> dataList) {
		this.dataList = dataList;
		this.inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (null == convertView) {
			convertView = inflater.inflate(R.layout.item_food_result_list,
					parent, false);
			holder = new ViewHolder();
			holder.addressTV = (TextView) convertView
					.findViewById(R.id.item_food_address_tv);
			holder.nameTV = (TextView) convertView
					.findViewById(R.id.item_food_name_tv);
			holder.telTV = (TextView) convertView
					.findViewById(R.id.item_food_tel_tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		data = dataList.get(position);
		holder.addressTV.setText(data.address);
		holder.nameTV.setText(data.name);
		holder.telTV.setText(data.phoneNum);
		return convertView;
	}

	static class ViewHolder {
		TextView nameTV;// 点名
		TextView telTV;// 电话
		TextView addressTV;// 地址
	}
}
